package com.yanlin.internalcommon.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * <p>标题：BigDecimalUtils</p>
 * <p>功能：</p>
 * <p>
 * 其他说明：
 * </p>
 * <p>审核：</p>
 * <p>重构：</p>
 * <p>创建日期：2025-06-11 04:56</p>
 *
 * @author yanlin
 */
public class BigDecimalUtils {

    public static double add(double v1, double v2) {
        BigDecimal value1 = BigDecimal.valueOf(v1);
        BigDecimal value2 = BigDecimal.valueOf(v2);
        return value1.add(value2).doubleValue();
    }

    public static double substract(double v1, double v2) {
        BigDecimal value1 = BigDecimal.valueOf(v1);
        BigDecimal value2 = BigDecimal.valueOf(v2);
        return value1.subtract(value2).doubleValue();
    }

    public static double multiply(double v1, double v2) {
        BigDecimal value1 = BigDecimal.valueOf(v1);
        BigDecimal value2 = BigDecimal.valueOf(v2);
        return value1.multiply(value2).doubleValue();
    }

    public static double divide(double v1, double v2) {
        BigDecimal value1 = BigDecimal.valueOf(v1);
        BigDecimal value2 = BigDecimal.valueOf(v2);
        return value1.divide(value2).doubleValue();
    }

    public static double setScale(double v, int scale, RoundingMode roundingMode){
        BigDecimal value = BigDecimal.valueOf(v);
        value = value.setScale(scale, roundingMode);
        return value.doubleValue();
    }

    private static class MainTest {
        public static void main(String[] args) {
            BigDecimal test1 = new BigDecimal(3.8);
            System.out.println("test1 = " + test1);
            BigDecimal test2 = BigDecimal.valueOf(3.8);
            System.out.println("test2=" + test2);
            double res = add(3.8, 1.2);
            System.out.println("res = " + res);
        }
    }
}
